package com.example.Aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.lang.reflect.Modifier;
import java.text.SimpleDateFormat;

//@Component
//@Aspect
@Slf4j
public class SpringAopImpAnnotation {

    private static SimpleDateFormat df = new SimpleDateFormat(
            "yyyy-MM-dd HH:mm:ss");

    SpringAopImpAnnotation() {
        log.info("SpringAopAnnotation 超级拦截器已加载 拦截所有含有AspectAnnotation注解的方法");
    }

    @Pointcut("@annotation(com.example.Annotation.AspectAnnotation)")
    private void aspectJMethod() {
    }

    @Before("aspectJMethod()")
    public void doBefore(JoinPoint joinPoint) {

        log.info("开始执行时间" + df.format(System.currentTimeMillis()));

    }

    @After(value = "aspectJMethod()")
    public void doAfter(JoinPoint joinPoint) {
        log.info("结束执行时间" + df.format(System.currentTimeMillis()));

    }

}
